﻿<input type="hidden" id="roleId" value="@ViewBag.UserRoleId" />
<script type="text/javascript">
    $(document).ready(function () {
        var roleId = $('#roleId').val();
        var oTable2 = $('#example').dataTable({
            "bServerSide": true,
            "sAjaxSource": "/UserRole/AjaxGetUserRoleManager?roleId="+roleId,
            "bProcessing": true,
            "sPaginationType": "full_numbers",
            "aoColumns":
[
{ "sName": "MenuId", "sTitle": "MenuId", "bVisible": false, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[0]; } },
{ "sName": "MenuName", "sTitle": "MenuName", "sWidth": 60, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[1]; } },
{ "sName": "URL", "sTitle": "URL", "sWidth": 120, "bVisible": false, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[2]; } },
{ "sName": "Title", "sTitle": "Title", "sWidth": 50, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[3]; } },
{ "sName": "Description", "sTitle": "Description", "sWidth": 50, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[4]; } },
{ "sName": "Parent", "sTitle": "Parent Menu", "sWidth": 30, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[5]; } },
{ "sName": "Parent", "sTitle": "Menu List", "sWidth": 70, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[6]; } },
{ "sName": "DisplayOrder", "sTitle": "Display Order", "sWidth": 20, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[7]; } },
{ "sName": "Action", "sTitle": "Action", "sWidth": 10, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[8]; } },
]
        });
        oTable2 = $('#example').dataTable();
    });
    function updateMenu(menuId) {
        var roleId = $('#roleId').val();
        var checkValue = $('#CHK_' + menuId).is(':checked');
        var sortOrder = $('#Sort_' + menuId).val();
        var selectValue = $('#Select_' + menuId).val();
        if (checkValue == true) {
            $.ajax({
                type: "POST",
                url: "/UserRole/UpdateRoleAccess?menuId=" + menuId + "&roleId=" + roleId + "&sortOrder=" + sortOrder + "&parentId=" + selectValue,
                success: function () {
                    oTable2 = $('#example').dataTable();
                    oTable2.fnDraw();
                }
            });
        }
        if (checkValue == false) {
            $.ajax({
                type: "POST",
                url: "/UserRole/DeleteRoleAccess?menuId=" + menuId + "&roleId=" + roleId,
                success: function () {
                    oTable2 = $('#example').dataTable();
                    oTable2.fnDraw();
                }
            });
        }
    }
    //    UpdateRoleAccess(string menuId,string roleId)
    //    DeleteRoleAccess(string menuId,string roleId)
</script>
<table class="data display datatable" id="example">
                <thead>
                    <tr>
                        <th>
                        </th>
                         <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                         <th>
                        </th>
                    </tr>
                </thead>
            </table>